var $skipRegister=$('#skip-register');
$skipRegister.off('tap').on('tap',function(e){
    window.location.href="index.html";
    e.preventDefault();
    return false;
});
var $personInfo=$('#personInfo');
var data=common.getLocalData('H5-agentInfo');
if(!data){
	window.location.href="login.html";
}else{
	var token=common.getToken();
}
if(data.id && token){
	var url=common.globalHost+common.getAgentDetailPort;
	var sendData={id:data.id,token:token};
	requestDataIsAuth({
		sendData:sendData,
		url:url,
		callback:function(data){
			isAuthInfo({
				dataList:data,
				targetSelector:$personInfo
			});
		}
	})
	
}else{
	window.location.href="login.html";
}
function isAuthInfo(options){
	var targetSelector=$(options.targetSelector);
	var dataList=options.dataList;
	var tempDom='<li><span>公司：</span><ins>'+dataList.companyName+'</ins></li>'+
				'<li><span>门店：</span><ins>'+dataList.storeName+'</ins></li>'+
				'<li><span>姓名：</span><ins>'+dataList.agentName+'</ins></li>'+
				'<li><span>身份证号码：</span><ins>'+dataList.idCard+'</ins></li>';
	targetSelector.html(tempDom);
};
function requestDataIsAuth(options) {
    var url=options.url;
    var sendData=options.sendData;
    var callback=options.callback;
    $.ajax({
        data:sendData,
        type: "POST",
        contentType: "application/x-www-form-urlencoded;charset=utf-8",
        dataType:"json",
        url:url,
        success:function(data){
            if(typeof data==="string"){
                data=JSON.parse(data);
            };
            if(data.code==101 ||data.code==102){
                console.log("token为空或者token失效");
                window.location.href='login.html';
            };
            if(!!data && data['code']=="0"){
                    data=data.res.data;
            };   
            callback(data);         
        },
        timeout:30000,
        error: function (XMLHttpRequest, textStatus, errorThrown) {
                common.errDialog("网络不畅，请稍后重试");
            
        }
    });
};